package proj.pt.web;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.ServletRequestUtils;

public class WebUtils {

	public static String getAction(HttpServletRequest request){
		Enumeration enm = request.getAttributeNames();
		String key;
		while(enm.hasMoreElements()){
			key = (String)enm.nextElement();
			if(key.startsWith("action_value")){
				return (String)request.getAttribute(key);
			}
		} //end while
		
		enm = request.getParameterNames();
		while(enm.hasMoreElements()){
			key = (String)enm.nextElement();
			if(key.startsWith("action_value")){
				return request.getParameter(key);
			}
		} //end while
		
		return null;
	}
	
	public static String getStringParameter(HttpServletRequest request, String attribute){
		try{
			String parameterValue = ServletRequestUtils.getStringParameter(request, attribute);
			if(parameterValue == null) return "";
			return parameterValue;
		} catch(Exception exp){
			return "";
		}
	}
	
}
